<!doctype html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title></title> 
    <link rel="stylesheet" href="../fonts/iconfont.css">
    <style type="text/css">
/* *{margin: 0;padding: 0;list-style: none;}         */
/* .outerNode{width: 505px;height: 406px;position: absolute;left: 50%;top: 50%;margin: -204px 0 0 -253.5px;border: 1px solid #a6a18d;border-radius:8px;box-shadow: 0 0 16px #a6a18d; }
.innerNode{width: 503px;height: 405px;border-top:1px solid #e1d1b9;border-left:1px solid #ceccbf;border-radius: 8px;overflow: hidden;border-right:1px solid #ceccbf;   }
.topNode{width: 100%;height: 198px;border-bottom: 1px solid #787463;background-size:cover; transition:.7s;position: relative;}
.lineNode{
    width: 100%;height: 46px;border-top: 1px solid #f9f7ee;border-bottom: 1px solid #a29d8a;background: url(musicimage/linebg.jpg) repeat-x; 
}
.progressNode{width: 440px;height: 18px;float: left;margin:13px 0 0 28px;position: relative; }
.progressNode .progressleft{
    width: 7px;height: 100%;position: absolute;left: 0;
}
.progressNode .progressright{
    width: 7px;height: 100%;position: absolute;right: 0;
}
.bottomNode{
    width: 100%;height: 157px;border-top: 1px solid #a29d8a;
    background: url(musicimage/bottombg.jpg) repeat-x;position: relative;
}
.lastNode{width: 75px;height: 74px;position: absolute;left: 118px;top: 39px;cursor: pointer;}
.playNode{width: 95px;height: 94px;position: absolute;cursor: pointer;}
.nextNode{width: 75px;height: 74px;position: absolute;cursor: pointer;}
.volumeNode{width: 37px;height: 32px;position: absolute;cursor: pointer;}
.no_volumeNode{width: 37px;height: 32px;position: absolute;cursor: pointer;}
.trueLine{position: absolute;left: 3px;top: 2px;height: 12px;width: 0%;border-radius: 6px; 
    border-right: 1px solid #787463;
}
.musicName{color: white;position: absolute;bottom: 2px;left: 5px;} */
    </style>
    <!-- <script src="//at.alicdn.com/t/font_1626342_p9jycql9i3.css"></script> -->
</head>
<body>
    <span class="iconfont icon-Mv" style="font-size: 40px"></span>

    <!-- outerNode 最外层的元素 -->
    <div class='outerNode'>
        <!-- innerNode 内层元素 -->
        <div class='innerNode'>
            <!-- topNode 封面图元素 -->
            <div class='topNode'>
                <!-- 音乐名称 -->
                <div class='musicName'></div>
            </div>
            <!-- lineNode 进度条元素 -->
            <div class='lineNode'>
                <!-- 进度条-->
                <div class='progressNode'>
                    <div class='progressleft'></div>
                    <div class='progressright'></div>
                    <!-- 真正的进度条 -->
                    <div class='trueLine'></div>
                </div>
            </div>
            <!-- bottomNode 空间元素 -->
            <div class='bottomNode'>
                <!-- lastNode 上一曲的按钮-->
                <div class='lastNode'><span class="iconfont icon-prev-full"></span></div>
                <!-- playNode 播放暂停的按钮 -->
                <div class='playNode'><span class="iconfont icon-tingzhi"></span></div>
                <!-- nextNode 下一曲的按钮 -->
                <div class='nextNode'><span class="iconfont icon-next-full"></span></div>
                <!-- volumeNode 静音或非静音的按钮-->
                <div class='volumeNode'><span class="iconfont icon-boyin"></span></div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        //播放暂停的按钮
        //playBln 控制播放暂停的布尔值
        var playBtn = document.querySelector('.playNode'),
        playBln = true,
        //控制声音的按钮
        //volumeBln 控制声音的布尔值
        volumeNode = document.querySelector('.volumeNode'),
        volumeBln = true,
        //进度条的选择器
        trueLine = document.querySelector('.trueLine'),
        //进度条外层的元素
        progressNode = document.querySelector('.progressNode'),
        //最外层元素
        outerNode = document.querySelector('.outerNode'),
        //选择一下封面背景
        topNode = document.querySelector('.topNode'),
        //下一首歌的按钮
        nextNode = document.querySelector('.nextNode'),
        //上一首歌的按钮
        lastNode = document.querySelector('.lastNode'),
        //音乐名称
        musicName = document.querySelector('.musicName');
        //给播放器添加js
        //创建audio对象
        var myAudio = new Audio();
        //给audio对象一个 src
        //所有的数据存在数组里面
        let allMusic = [{
            'MusicSrc':'https://music.163.com/song/media/outer/url?id=33894312.mp3',
            'MusicPic':'music/pic/fmt01.jpg',
            'MusicName':'AcousticGuitar1'
        },{
            'MusicSrc':'https://music.163.com/song/media/outer/url?id=405998841.mp3',
            'MusicPic':'music/pic/fmt02.png',
            'MusicName':'AmazingGrace'
        },{
            'MusicSrc':'music/mus/FeelsGood2B.mp3',
            'MusicPic':'music/pic/fmt03.jpg',
            'MusicName':'FeelsGood2B'
        },{
            'MusicSrc':'music/mus/FunBusyIntro.mp3',
            'MusicPic':'music/pic/fmt04.jpg',
            'MusicName':'FunBusyIntro'
        },{
            'MusicSrc':'music/mus/GreenDaze.mp3',
            'MusicPic':'music/pic/fmt05.jpg',
            'MusicName':'GreenDaze'
        },{
            'MusicSrc':'music/mus/Limosine.mp3',
            'MusicPic':'music/pic/fmt06.jpg',
            'MusicName':'Limosine'
        }],Index = 0;
        myAudio.src = allMusic[Index].MusicSrc;
        //给封面赋值
        topNode.style.backgroundImage = 'url('+allMusic[Index].MusicPic+')';
        //给音乐名称
        musicName.innerHTML = allMusic[Index].MusicName;
        //谷歌浏览器不允许直接play
        //myAudio.play();
        //播放暂停的事件
        playBtn.onclick = function(){
            //myAudio.play();
            playBln = !playBln;
            if(playBln == false){
                myAudio.play();
            }
            else{
                myAudio.pause();
            }
        };
        //声音的事件
        volumeNode.onclick = function(){
            volumeBln = !volumeBln;
            if(volumeBln == false){
                myAudio.volume = 0;
                this.className = 'no_volumeNode';
            }
            else{
                myAudio.volume = 1;
                this.className = 'volumeNode';
            }
        };
        //播放时 进度条的长度控制计算
        myAudio.addEventListener('timeupdate',function(){
            trueLine.style.width = myAudio.currentTime / myAudio.duration * 100 + '%';
        });
        //点击progressNode元素 让进度条直接到达这个位置
        progressNode.onclick = function(e){
            var ev = e || event;
            //算法 就是 算出 点击的位置 在 外层进度条的 多少像素
            //需要一个鼠标坐标点 减去 外层元素的 offsetLeft 和 最外层元素的offsetLeft 
            // 320秒 *  0.50 = 160秒
            myAudio.currentTime = myAudio.duration * ((ev.clientX - (this.offsetLeft + outerNode.offsetLeft))/this.offsetWidth);
            trueLine.style.width = ((ev.clientX - (this.offsetLeft + outerNode.offsetLeft))/this.offsetWidth) * 100 + '%';
        };
        //下一首歌的事件
        nextNode.onclick = function(){
            Index ++;
            if(Index == allMusic.length){
                Index = 0;
            }
            MusicPlayFn();
        };
        //音乐播放的函数
        function MusicPlayFn(){
            myAudio.src = allMusic[Index].MusicSrc;
            myAudio.currentTime = 0;
            trueLine.style.width = '0%';
            if(playBln == false){
                myAudio.play();
            }
            else{
                myAudio.pause();
            }
            //给封面赋值
            topNode.style.backgroundImage = 'url('+allMusic[Index].MusicPic+')';
            //给音乐名称
            musicName.innerHTML = allMusic[Index].MusicName;
        }
        //上一首歌的点击事件
        lastNode.onclick = function(){
            Index --;
            if(Index == -1){
                Index = allMusic.length-1;
            }
            MusicPlayFn();
        };
    </script>
</body>
</html>